package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.PathTreeDto;
import com.ihisomp.service.IOmpPagePathService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 标题: OmpPagePathController.java
 * 业务描述: 运营管理菜单维护 前端控制器
 * 作者: zy
 * 日期: 2021/9/13
 * 版本: V1.0
 */
@RestController
@Api(value = "系统菜单信息", tags = "系统菜单信息")
@RequestMapping("/ompPagePath")
public class OmpPagePathController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private IOmpPagePathService ompPagePathService;

    /**
     * 获取程序树形集合数据
     *
     * @return
     */
    @GetMapping("/tree")
    @ApiOperation("获取菜单集合")
    public Result getPathTree() {
        logger.info("获取程序树形集合数据");
        Result result = ompPagePathService.getPathTree();
        return result;
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param pathTreeDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "pathTreeDto", value = "系统菜单树型数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) PathTreeDto pathTreeDto) {
        logger.info("分页查询：page={}，size={}, pathTreeDto={}", page, size, pathTreeDto);
        Result result = ompPagePathService.search(page, size, pathTreeDto);
        return result;
    }

    /**
     * 文件夹及程序查询
     *
     * @return
     */
    @GetMapping("/listSelect")
    @ApiOperation("查询文件夹及程序")
    public Result listSelect() {
        logger.info("查询文件夹及程序");
        Result result = ompPagePathService.listSelect();
        return result;
    }

    /**
     * 新增数据
     *
     * @param pathTreeDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "pathTreeDto", value = "系统菜单树型数据类", required = true)
    public Result add(@RequestBody PathTreeDto pathTreeDto) {
        logger.info("新增数据：pathTreeDto={}", pathTreeDto);
        Result result = ompPagePathService.add(pathTreeDto);
        return result;
    }

    /**
     * 删除数据
     *
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("删除数据")
    @ApiImplicitParam(name = "id", value = "系统菜单主键", required = true)
    public Result delete(@PathVariable("id") String id) {
        logger.info("新增数据：id={}", id);
        Result result = ompPagePathService.delete(id);
        return result;
    }

    /**
     * 更新数据
     *
     * @param id
     * @param pathTreeDto
     * @return
     */
    @PostMapping("/update/{id}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统菜单主键", required = true),
            @ApiImplicitParam(name = "pathTreeDto", value = "系统菜单树型数据类", required = true)})
    public Result update(@PathVariable("id") String id, @RequestBody PathTreeDto pathTreeDto) {
        logger.info("更新数据：id={}， pathTreeDto={}", id, pathTreeDto);
        Result result = ompPagePathService.update(id, pathTreeDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "id", value = "系统菜单主键", required = true)
    public Result get(@PathVariable("id") String id) {
        logger.info("查询数据：id={}", id);
        Result result = ompPagePathService.get(id);
        return result;
    }

    /**
     * 更新程序状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("status/{id}/{status}")
    @ApiOperation("更新菜单状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统菜单主键", required = true),
            @ApiImplicitParam(name = "status", value = "系统菜单状态", required = true)})
    public Result updateStatus(@PathVariable("id") String id,
                               @PathVariable("status") int status) {
        logger.info("更新程序状态：id={}, status={}", id, status);
        Result result = ompPagePathService.updateStatus(id, status);
        return result;
    }

    /**
     * 查询全部程序数据
     *
     * @return
     */
    @GetMapping("/getList")
    @ApiOperation("查询菜单全部数据")
    public Result getPagePathList() {
        logger.info("查询全部程序数据");
        Result result = ompPagePathService.getPagePathList();
        return result;
    }

}
